package hah;

public class delete {
    public int removeDuplicates(int[] nums) {
            if(nums.length==0){
                return 0;
            }
            if (nums.length==1){
                return 1;
            }
            int n=nums.length;
            int i=0;
            int j=1;
            while (j<=n-1){
                if (nums[i]==nums[j]){
                    j++;
                }else {
                    i++;
                    nums[i]=nums[j];
                }
            }
            return i;
    }
    public int trap(int[] height){
            int sum=0;
            for (int i=0;i< height.length;i++){
                sum+= height[i];
            }
            int left=0;
            int right= height.length-1;
            int high=1;
            int total=0;
            while (left<=right){
                while (height[left]<high){
                    left++;
                }
                while (height[right]<high){
                    right--;
                }
                total+=right-left+1;
                high++;
            }
            return total-sum;
    }
    public void reverseString(char[] s) {
            int len=s.length;
            int left=0;
            int right=len-1;
            char temp=' ';
            while (left<=right){
                temp=s[left];
                s[left]=s[right];
                s[right]=temp;
                left++;
                right--;
            }
    }
}
